<?php
session_start();
require_once( 'test_header.php');
require_once( CLASSMATE_ROOT.'/include/functions/mongo_connect.function.php' );

class test_class_user_reg_process extends UnitTestCase{

	 private $db_connect;

	 function setUp(){
	 	 
		 //建立数据库连接,并选择测试数据库
		 $this->db_connect = mongo_connect( '127.0.0.1' , 'test' );
		 //选择或建立测试需要的数据表
	 	 $collection = $this->db_connect->user;		 

	 }
	 function tearDown(){
	 }

	 //测试用户成功注册的情况
	 function test_user_do_reg_success(){

	 	 //mock 用户的输入
	 	 $request = array( 'username' => rand() , 'password' => rand() );
		 $user_reg_process = new user_reg_process( $this->db_connect );

		 $reg_result = $user_reg_process->do_reg( $request );
		 $this->assertTrue( $reg_result );

		 //不能重复注册
		 $this->expectException();
	 	 $user_reg_process->do_reg( $request );

		 //刚注册的用户应该存在
		 $has_reg_result = $user_reg_process->has_reg( $request['username'] );
	 	 $this->assertTrue( $has_reg_result );
	 }	 
}

$test = new test_class_user_reg_process();
$test->run( new HtmlReporter() );
